from dao.task_site_dao import TaskSiteDAO
from models import TaskSite


class TaskSiteService:
    def __init__(self):
        self.dao = TaskSiteDAO()

    def create_task_site(self, type_name: str, site_name: str, list_link: str, method: str, param: str, cookie: str,
                         user_agent: str, status: int, time_interval: int):
        new_task_site = TaskSite(
            type_name=type_name,
            site_name=site_name,
            list_link=list_link,
            method=method,
            param=param,
            cookie=cookie,
            user_agent=user_agent,
            status=status,
            time_interval=time_interval
        )
        return self.dao.create_task_site(new_task_site)

    def update_site_execute_time(self, id):
        """
        更新最后采集的时间
        :param id:
        :return:
        """
        return self.dao.update_site_execute_time(id)

    def get_all_task_sites(self, type="new"):
        return self.dao.get_all_task_sites(type)

    def get_task_site_by_id(self, task_site_id: int):
        return self.dao.get_task_by_id(task_site_id)
